package com.net.xpay.admin.secutiry;

import org.springframework.security.authentication.AuthenticationProvider;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;
import org.springframework.stereotype.Component;

/**
  on 2018/9/12.
 */
@Component
public class AutoLoginAuthenticationProvider implements AuthenticationProvider {
    @Override
    public Authentication authenticate(Authentication authentication) throws AuthenticationException {
        AutoLoginToken token = (AutoLoginToken) authentication;

        return new Operator(token.getUser(), token.getClientFrom());
    }

    @Override
    public boolean supports(Class<?> authentication) {
        return AutoLoginToken.class.isAssignableFrom(authentication);
    }
}
